package scau.erps.view.decision.sand;

import java.util.List;

import scau.erps.app.Erps;
import scau.erps.entity.Team;
import scau.erps.entity.TeamOrder;
import scau.erps.service.TeamOrderService;
import scau.erps.service.impl.TeamOrderServiceImpl;
import scau.erps.util.CalculateQuarter;

/**
 * 应付款盘面模拟面板
 * @author DCJ
 *
 */
public class ReceivablePanel extends SandPanelTemplateFor4Q{
	private static final long serialVersionUID = 1L;
	public ReceivablePanel(){
		super();
		this.titleLabel.setText("应收款");
		this.setTextFieldValue();
	}
	@Override
	public void setTextFieldValue() {
		Team team = Erps.getCurrentTeam();	
		String time=Erps.getSand().getTime();
		int team_Id = team.getId();
		int q1 = 0;
		int q2 = 0;
		int q3 = 0;
		int q4 = 0;
		int amount=0;
		TeamOrderService teamOrderService =Erps.getIocInstance().get(TeamOrderServiceImpl.class);
        List<TeamOrder> list=teamOrderService.getTeamOrderByStatus(team_Id, "已交货");
        String q1Time=CalculateQuarter.addOneQuarter(time);
        String q2Time=CalculateQuarter.addTwoQuarter(time);
        String q3Time=CalculateQuarter.addThreeQuarter(time);
        String q4Time=CalculateQuarter.addFourQuarter(time);
        
        for (TeamOrder teamOrder:list){
        	String receivable=teamOrder.getReceivable();
        	if(teamOrder.getTie()==0){
        		amount=teamOrder.getTotal()-teamOrder.getPenalty();
        	}
        	else{
        		amount=teamOrder.getTie();
        	}
        	if (Integer.parseInt(Erps.getSand().getStep())<=21){        //Y0Q0特殊处理
        	    if (receivable.equals(time))   q1=q1+amount;
        		if (receivable.equals(q1Time)) q2=q2+amount;
        	    if (receivable.equals(q2Time)) q3=q3+amount;
        	    if (receivable.equals(q3Time)) q4=q4+amount;
        	}
        	else{
            	if (receivable.equals(q1Time)) q1=q1+amount;
            	if (receivable.equals(q2Time)) q2=q2+amount;
            	if (receivable.equals(q3Time)) q3=q3+amount;
            	if (receivable.equals(q4Time)) q4=q4+amount;
        	}
        }

		this.jtx_1q.setText(Integer.toString(q1));		
		this.jtx_2q.setText(Integer.toString(q2));
		this.jtx_3q.setText(Integer.toString(q3));
		this.jtx_4q.setText(Integer.toString(q4));		
	}
	public void refresh(){
		this.setTextFieldValue();
	}
}
